package vanjalee.bs.com.control.model;

import java.util.ArrayList;
import java.util.List;

public class Item {

	protected ItemType itemType;

	protected String whereToGet;
	protected String furtherInfo;

	protected boolean upgradable = false;
	protected boolean special = false;
	
	public String getWhereToGet() {
		return whereToGet;
	}

	public void setWhereToGet(String whereToGet) {
		this.whereToGet = whereToGet;
	}

	public String getFurtherInfo() {
		return furtherInfo;
	}

	public void setFurtherInfo(String furtherInfo) {
		this.furtherInfo = furtherInfo;
	}

	public boolean isUpgradable() {
		return upgradable;
	}

	public void setUpgradable(boolean upgradable) {
		this.upgradable = upgradable;
	}

	public boolean isSpecial() {
		return special;
	}

	public void setSpecial(boolean special) {
		this.special = special;
	}

	public ItemType getItemType() {
		return itemType;
	}

	public void setItemType(ItemType itemType) {
		this.itemType = itemType;
	}
	
	public static void setItemType(Item item, String remark) {		
		item.setFurtherInfo(remark);
		remark = remark.toLowerCase();
		if (remark.contains("event") || remark.contains("great hunt")) {
			item.setItemType(ItemType.EVENT);
		} else if (item.getWhereToGet().toLowerCase()
				.equals("wiley's war wagon")) {
			item.setItemType(ItemType.MEDAL);
		} else if (remark.contains("ocho")) {
			item.setItemType(ItemType.OCHO);
		} else if (remark.contains("crafted")) {
			item.setItemType(ItemType.CRAFTED);
		} else if (remark.contains("assembled")) {
			item.setItemType(ItemType.ASSEMBLED);
		} else if (remark.contains("ember")) {
			item.setItemType(ItemType.EMBER);
		} else if (remark.contains("boss")) {
			item.setItemType(ItemType.BOSS);
		} else if (remark.contains("quest")) {
			item.setItemType(ItemType.QUEST);
		} else if (remark.contains("referral")) {
			item.setItemType(ItemType.REFERRAL);
		} else if (remark.contains("gold license")) {
			item.setItemType(ItemType.GOLD_LICENCE);
		} else if (remark.contains("silver license")) {
			item.setItemType(ItemType.SILVER_LICENCE);
		} else if (remark.contains("promo")) {
			item.setItemType(ItemType.PROMO);
		} else if (remark.contains("tournament")) {
			item.setItemType(ItemType.TOURNAMENT_PRIZE);
		} else if (remark.contains("casino")) {
			item.setItemType(ItemType.CASINO);
		}
		if (remark.contains("upgradable")) {
			item.setUpgradable(true);
		}
		if (remark.contains("special")) {
			item.setSpecial(true);
		}
	}
	
	public static String getEvent(Item item) {
		String remark = item.getFurtherInfo().toLowerCase();
		if (item.getItemType().equals(ItemType.EVENT)) {
			if (remark.contains("great hunt")) {
				return "Great Hunt Event";
			} else if (remark.contains("maelstrom ")) {
				return "Maelstrom Event";
			} else if (remark.contains("twilight gate")) {
				return "Twilight Gate Event";
			} else if (remark.contains("red fleet")) {
				return "Red Fleet Event";
			} else if (remark.contains("20000")) {
				return "20000 Leagues Event";
			} else if (remark.contains("easter")) {
				return "Easter Event";
			} else if (remark.contains("christmas")) {
				return "Christmas Event";
			} else if (remark.contains("world cup")) {
				return "World Cup Event";
			} else if (remark.contains("patricks")) {
				return "St Patricks Day Event";
			} else if (remark.contains("vday")) {
				return "Vday Event";
			} else if (remark.contains("oktober")) {
				return "Oktoberfest Event";
			} else if (remark.contains("halloween")) {
				return "Halloween Event";
			}
			return "Invalid event";
		}
		return "Invalid item type";
	}
	
	public static List<String> findNamesOfIncompatibleWith(Item item){
		List<String> results = new ArrayList<>();		
		String raw = item.getFurtherInfo();
		if (raw.contains("Cannot be used with")) {
			raw = raw.substring(raw.indexOf("Cannot be used with") + 20);			
			if (raw.endsWith(".")){
				raw = raw.substring(0, raw.length() - 2);
			}						
			if (raw.contains("or")) {
				String [] split = raw.split(" or ");
				for (int i = 0; i<split.length; i++) {				
					results.add(split[i]);
				}	
			} else {
				results.add(raw);
			}					
		}
		return results;
	}
	
}
